package com.bootdo.blog.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.blog.domain.InspectionDO;
import com.bootdo.blog.service.InspectionService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;




/**
 * 
 * 
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2021-03-07 10:38:32
 */
@Controller
@RequestMapping("/blog/inspection")
public class InspectionController {
	@Autowired
	private InspectionService inspectionService;
	
	@GetMapping()
	@RequiresPermissions("blog:inspection:inspection")
	String Inspection(){
	    return "blog/inspection/inspection";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("blog:inspection:list")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<InspectionDO> inspectionList = inspectionService.list(query);
		int total = inspectionService.count(query);
		PageUtils pageUtils = new PageUtils(inspectionList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("blog:inspection:save")
	String add(){
	    return "blog/inspection/add";
	}
	@GetMapping("/edit/{id}")
	@RequiresPermissions("blog:inspection:update")
	String edit(@PathVariable("id") Integer inspectionId, Model model){
		InspectionDO inspectionDO = inspectionService.get(inspectionId);
		model.addAttribute("inspectionDO", inspectionDO);
	    return "blog/inspection/edit";
	}
	/**
	 * 信息
	 */
	@RequestMapping("/info/{inspectionId}")
	@RequiresPermissions("blog:inspection:info")
	public R info(@PathVariable("inspectionId") Integer inspectionId){
		InspectionDO inspection = inspectionService.get(inspectionId);
		return R.ok().put("inspection", inspection);
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("blog:inspection:save")
	public R save( InspectionDO inspection){
		if(inspectionService.save(inspection)>0){
			return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("blog:inspection:update")
	public R update( InspectionDO inspection){
		inspectionService.update(inspection);
		
		return R.ok();
	}
	
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("blog:inspection:remove")
	public R remove( @RequestParam("id")Integer inspectionId){
		if(inspectionService.remove(inspectionId)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("blog:inspection:remove")
	public R remove(@RequestParam("ids[]") Integer[] inspectionIds){
		inspectionService.batchRemove(inspectionIds);
		
		return R.ok();
	}
	
}
